#ifndef CUSTOMGRAPHICSSCENE_H
#define CUSTOMGRAPHICSSCENE_H

#include <QGraphicsScene>
#include "customgraphics.h"

class QGraphicsSceneMouseEvent;
class QGraphicsSceneContextMenuEvent;
class QGraphicsView;
class QKeyEvent;

class CustomGraphicsScene : public QGraphicsScene
{
    Q_OBJECT

public:
    enum Mode { Normal, CreateItem };

    explicit CustomGraphicsScene(QGraphicsView* view, QObject *parent = nullptr);

    void setMode(Mode mode);
    void setComponentTypeToCreate(ComponentType type);

signals:
    void componentCreated(HmiComponent* item);
    // 转发键盘操作请求
    void copyRequestFromScene();
    void pasteRequestFromScene(const QPointF& scenePos); // 传递粘贴位置
    void deleteRequestFromScene();

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
    void keyPressEvent(QKeyEvent *keyEvent) override;
    void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent) override;

private:
    Mode m_mode;
    ComponentType m_componentTypeToCreate;
    QGraphicsView* m_view;
};

#endif // CUSTOMGRAPHICSSCENE_H
